cmake_minimum_required(VERSION 3.6.0)

# Inhibit all of CMake's own NDK handling code.
set(CMAKE_SYSTEM_VERSION 1)

set(CMAKE_SYSTEM_NAME Linux)

list(APPEND CMAKE_FIND_ROOT_PATH "${OHOS_NDK}")
if(NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM)
  set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
endif()

if(NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY)
  set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
endif()

if(NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE)
  set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
endif()

if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE)
  set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
endif()

set (CMAKE_LINKER "${OHOS_NDK}/bin/lld")

set(CMAKE_C_COMPILER_ID_RUN TRUE)
set(CMAKE_CXX_COMPILER_ID_RUN TRUE)
set(CMAKE_C_COMPILER_ID Clang)
set(CMAKE_CXX_COMPILER_ID Clang)
set(CMAKE_C_COMPILER_VERSION 9.0)
set(CMAKE_CXX_COMPILER_VERSION 9.0)
set(CMAKE_C_STANDARD_COMPUTED_DEFAULT 11)
set(CMAKE_CXX_STANDARD_COMPUTED_DEFAULT 15)
set(CMAKE_C_COMPILER_FRONTEND_VARIANT "GNU")
set(CMAKE_CXX_COMPILER_FRONTEND_VARIANT "GNU")

set(CMAKE_C_STANDARD_LIBRARIES_INIT "-latomic -lm")
set(CMAKE_CXX_STANDARD_LIBRARIES_INIT "${CMAKE_C_STANDARD_LIBRARIES_INIT}")

set(CMAKE_CXX_FLAGS           "-fuse-ld=lld -isystem ${OHOS_NDK}/include/c++/v1 ${CMAKE_CXX_FLAGS}")
set(CMAKE_C_COMPILER        "${OHOS_NDK}/bin/clang")
set(CMAKE_CXX_COMPILER      "${OHOS_NDK}/bin/clang++")
set(STD_LINKER_FLAGS "-L ${OHOS_NDK}/lib/x86_64-unknown-linux-gnu -Wl,-rpath,${OHOS_NDK}/lib/x86_64-unknown-linux-gnu -lc++")
set(CMAKE_SHARED_LINKER_FLAGS "${STD_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS "${STD_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS    "${STD_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}")
